﻿using System;
using System.Collections.Generic;
using System.Linq;
using Medianamik.Core;
using NUnit.Framework;

namespace Medianamik.Tests.Integration.Medianamik.Core
{
    [TestFixture]
    [Ignore]
    public class NodeTypeManagerTest
    {

        [Test]
        public void CreateBasicTypeOnRoot()
        {
            var nt = new NodeType("TESTBT", false, false,false,false,null,false,new List<NodeType>(){},new List<Node>(){},new List<TypeTemplate>(){}, null);
            NodeTypeManager.SaveType(nt);


            Assert.AreEqual(nt.Name,"TESTBT");
            Assert.AreEqual(nt.IsAbstract,false);
            Assert.AreEqual(nt.IsGenerated,false);
            Assert.AreEqual(nt.IsInheritable,false);
            Assert.AreEqual(nt.IsManyToMany,false);
            Assert.AreEqual(nt.IsSystem,false);

            NodeTypeManager.DeleteNodeType(nt);
        }

        [Test]
        public void TestDuplicate()
        {
            bool ok = false;
            var nt = new NodeType("TESTBT", false, false, false, false, null, false, new List<NodeType>() { }, new List<Node>() { }, new List<TypeTemplate>() { }, null);
            NodeTypeManager.SaveType(nt);

            try
            {
                var nt2 = new NodeType("TESTBT", false, false, false, false, null, false, new List<NodeType>() {},
                                       new List<Node>() {}, new List<TypeTemplate>() {}, null);
                NodeTypeManager.SaveType(nt2);
                NodeTypeManager.DeleteNodeType(nt2);
            }
            catch (CoreException)
            {
                //CoreException souhaité
                ok = true;
            }
            finally
            {
                NodeTypeManager.DeleteNodeType(nt);
            }
            if(!ok)
                throw new Exception("CoreException attendu");
        }


        [Test]
        public void BlaBlaBla()
        {
            var types =
                NodeTypeManager.GetAllTypes(true)
                    .Where(t => t.IsGenerated)
                    .OrderByDescending(t => t.Depth)
                    .Select(t => t.Name);

            Assert.That(types.Count(), Is.Not.Empty);
        }
   
    }
}